/**
 * 项目的路由
 */
import { createRouter,createWebHistory   } from "vue-router";


//创建路由
const defaultRouter = createRouter({
    history: createWebHistory(),
    routes: [
        { path: "/login", component: () => import("../pages/Login.vue") },
        { path: "/", component: () => import("../components/layout/Index.vue") }
    ]
});

//缓存问题

const token  = sessionStorage.getItem("token");

defaultRouter.beforeEach(async (from ,to ,next)=>{
    if(from.path === '/login'){
        next();
    }else if(from.path !== '/login' && token != null?true:false ){
        console.log(1111);
        
        next();
    }else{
        next('/login');
    }
})

//导出一个变量
export default defaultRouter;